home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / library / help / tcl / files / bsearch next >
Encoding:
Text File  |  1993-10-26  |  1.5 KB  |  27 lines  |  [TEXT/$Tcl]

  1.  
  2.  
  3.           bsearch fileId key ?retvar? ?compare_proc?
  4.                Search an opened file fileId containing lines  of  text
  5.                sorted  into ascending order for a match.  Key contains
  6.                the string to match.  If retvar is specified, then  the
  7.                line  from the file is returned in retvar, and the com-
  8.                mand returns 1 if key was found, and 0  if  it  wasn't.
  9.                If  retvar is not specified or is a null name, then the
  10.                command returns the line that was found,  or  an  empty
  11.                string if key wasn't found.
  12.  
  13.                By default,  the  key  is  matched  against  the  first
  14.                white-space separated field in each line.  The field is
  15.                treated as an ASCII string.  If compare_proc is  speci-
  16.                fied,  then  it  defines the name of a Tcl procedure to
  17.                evaluate against each line read from  the  sorted  file
  18.                during   the   execution   of   the   bsearch  command.
  19.                Compare_proc takes two arguments, the key  and  a  line
  20.                extracted  from  the  file.  The compare routine should
  21.                return a number less than zero if the key is less  than
  22.                the  line, zero if the key matches the line, or greater
  23.                than zero if the key is greater  than  the  line.   The
  24.                file must be sorted in ascending order according to the
  25.                same criteria compare_proc uses to compare the key with
  26.                the line, or errouenous results will occur.
  27.